package com.antis.olsl.base;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewbinding.ViewBinding;

import com.antis.olsl.base.databinding.FragmentBaseBinding;

/**
 * Fragment的基类
 * Created by 陈健宇 at 2018/10/21
 */
public abstract class BaseFragment<T extends ViewBinding> extends AbstractLazyLoadFragment {

    public FragmentBaseBinding baseBinding;
    public T viewBinding;
    protected Activity mActivity;
    protected View mView;

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        mActivity = (Activity) context;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        baseBinding = FragmentBaseBinding.inflate(getLayoutInflater());
        return baseBinding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        viewBinding = getViewBinding();
        initView(view);
    }

    protected abstract T getViewBinding();

    protected abstract void initView(View view);//初始化控件

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        baseBinding = null;
    }

    @Override
    protected void onLazyLoadData() {
        loadData();
    }

    protected abstract void loadData();//加载数据
}